import service from '@/utils/axios';
import { IResponseType, PageVO, success } from '@/api/common';
import {
    ContentAddRO,
    ContentEditRO,
    ContentHotVO,
    ContentPageRO,
    ContentShowVO,
    ContentVO,
    CountVO
} from '@/api/content/content/content';

export const getHot = () => {
    return service<IResponseType<ContentHotVO[]>>({
        url: '/content/content/hot',
        method: 'post'
    });
};

export const getContentShowPage = (pageRO: ContentPageRO) => {
    return service<IResponseType<PageVO<ContentShowVO>>>({
        url: '/content/content/showPage',
        method: 'post',
        data: pageRO
    });
};

export const getContentInfo = (id: string) => {
    return service<IResponseType<ContentVO>>({
        url: '/content/content/get/' + id,
        method: 'post'
    });
};

export const getContentPage = (pageRO: ContentPageRO) => {
    return service<IResponseType<PageVO<ContentVO>>>({
        url: '/content/content/page',
        method: 'post',
        data: pageRO
    });
};

export const addContent = async (data: ContentAddRO) => {
    return service<IResponseType<void>>({
        url: '/content/content/add',
        method: 'post',
        data
    }).then((d) => success(d, '添加成功'));
};

export const editContent = async (data: ContentEditRO) => {
    return service<IResponseType<void>>({
        url: '/content/content/edit',
        method: 'post',
        data
    }).then((d) => success(d, '修改成功'));
};

export const remove = async (ids: string) => {
    return service<IResponseType<void>>({
        url: '/content/content/remove/' + ids,
        method: 'post'
    }).then((d) => success(d, '修改成功'));
};

export const support = (id: string, isSupport: boolean) => {
    return service<IResponseType<void>>({
        url: `/content/content/support/${id}/${isSupport}`,
        method: 'post'
    });
};

export const favorite = (id: string, isFavorite: boolean) => {
    return service<IResponseType<void>>({
        url: `/content/content/favorite/${id}/${isFavorite}`,
        method: 'post'
    });
};

export const getAllCount = () => {
    return service<IResponseType<CountVO>>({
        url: '/content/content/count',
        method: 'post'
    });
};
